-
Notifications
You must be signed in to change notification settings - Fork 8
Azam/feature/hardcoded biorthogonal coefficients #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azam/feature/hardcoded biorthogonal coefficients #457
Conversation
…nal_coefficients' into azam/feature/hardcoded_biorthogonal_coefficients
…eature/hardcoded_biorthogonal_coefficients # Conflicts: # SeQuant/domain/mbpt/biorthogonalization.cpp
…eature/hardcoded_biorthogonal_coefficients
…eature/hardcoded_biorthogonal_coefficients
…se use computed ones
…coded(rational) and computed(double) coeffs
…ded_biorthogonal_coefficients' into azam/feature/hardcoded_biorthogonal_coefficients
…eature/hardcoded_biorthogonal_coefficients
…eature/hardcoded_biorthogonal_coefficients
ae2bb57 to
f8f3115
Compare
…nd backend-neutral code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces hardcoded (exact) biorthogonalization coefficients and NNS projection weights to avoid numerical precision loss, and updates evaluation/tests to use the new NNS projection path.
Changes:
- Add hardcoded biorthogonal coefficient generation (ranks 1–5) with memoization fallback to computed coefficients for higher ranks.
- Introduce NNS projection weights (hardcoded up to rank 5, computed beyond) and TA/BTAS projection helpers.
- Update spintracing normalization behavior and adjust evaluation unit tests accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
SeQuant/domain/mbpt/biorthogonalization.hpp |
Declares hardcoded coefficient APIs, adds NNS projector weights + TA/BTAS projection helpers. |
SeQuant/domain/mbpt/biorthogonalization.cpp |
Implements hardcoded coefficient matrices, memoized coefficient selection, and computed NNS weights. |
SeQuant/domain/mbpt/spin.cpp |
Simplifies S normalization factor handling in closed_shell_CC_spintrace_v2. |
SeQuant/core/eval/result.hpp |
Removes Result-level NNS projection implementation (migrated out). |
SeQuant/core/eval/eval.hpp |
Removes EvalMode::BiorthogonalNNSProject and evaluate_biorthogonal_nns_project. |
tests/unit/test_eval_ta.cpp |
Updates TA evaluation to call the new NNS projection helper and adds rank-4 NNS test. |
tests/unit/test_eval_btas.cpp |
Updates BTAS evaluation to call the new NNS projection helper and adjusts permutation averaging. |
tests/unit/test_spin.cpp |
Updates comments/section naming reflecting new spintracing behavior. |
CMakeLists.txt |
Adds compile definitions for evaluation-related feature macros. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| auto memoize = []<typename T>(container::map<std::pair<std::size_t, double>, | ||
| std::optional<T>>& cache, | ||
| std::mutex& mutex, std::condition_variable& cv, | ||
| std::pair<std::size_t, double> key, | ||
| auto compute_fn) -> const T& { | ||
| { | ||
| std::unique_lock<std::mutex> lock(mutex); | ||
| auto [it, inserted] = cache.try_emplace(key, std::nullopt); | ||
| if (!inserted) { | ||
| cv.wait(lock, [&] { return it->second.has_value(); }); | ||
| return it->second.value(); | ||
| } | ||
| } | ||
|
|
||
| T result = compute_fn(); | ||
|
|
||
| { | ||
| std::lock_guard<std::mutex> lock(mutex); | ||
| cache[key] = std::move(result); | ||
| cv.notify_all(); | ||
| return cache[key].value(); | ||
| } |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The local memoize helper can deadlock if compute_fn throws: the inserted cache entry stays std::nullopt and any concurrent callers will wait forever on the condition_variable. Add exception handling to ensure the cache is updated/erased and cv.notify_all() is called on failure.
| static std::mutex cache_mutex; | ||
| static std::condition_variable cache_cv; | ||
| static container::map<CacheKey, CacheValue> cache; | ||
|
|
||
| CacheKey key{n_particles, threshold}; | ||
|
|
||
| { | ||
| std::unique_lock<std::mutex> lock(cache_mutex); | ||
| auto [it, inserted] = cache.try_emplace(key, std::nullopt); | ||
| if (!inserted) { | ||
| cache_cv.wait(lock, [&] { return it->second.has_value(); }); | ||
| return it->second.value(); | ||
| } | ||
| } |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nns_projection_weights memoization can deadlock: if computing coefficients throws, the cache entry remains std::nullopt and any waiting threads will block forever. Consider storing an exception state (e.g., std::exception_ptr) or erasing the key and notifying in a catch block so waiters don’t hang.
…eval-backends `SQ/eval` backends reorganization
This branch provides hardcoded biorthgonal and nns coefficients